package com.example.sofa_module.detail;

import com.example.common.mvvm.BaseEntity;
import com.example.common.mvvm.model.BaseRepository;
import com.example.network_sdk.RetrofitManager;
import com.example.sofa_module.ApiService;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;

public class CommentRepository extends BaseRepository {
    public Observable<BaseEntity>requestCommentList(int id,long itemId,int pageCount,long userId){
        Observable<CommentEntity> commentEntityObservable = RetrofitManager.getInstance().getRetrofit().create(ApiService.class).requestDetailComment(id, itemId, pageCount, userId);
        return commentEntityObservable.map(new Function<CommentEntity, BaseEntity>() {
            @Override
            public BaseEntity apply(@NonNull CommentEntity commentEntity) throws Exception {
                return commentEntity;
            }
        });
    }

    public Observable<BaseEntity>requestAddComment(String commentText,Integer height,String  image_url,Integer itemId,
                                                   Integer userId,String video_url,Integer width){
        Observable<AddComEntity>addComEntityObservable=RetrofitManager.getInstance().getRetrofit().create(ApiService.class).requestAddComment(commentText,height,image_url,itemId,userId,video_url,width);
        return addComEntityObservable.map(new Function<AddComEntity, BaseEntity>() {
            @Override
            public BaseEntity apply(@NonNull AddComEntity addComEntity) throws Exception {
                return addComEntity;
            }
        });
    }

    public Observable<BaseEntity>requestDelComment(long commentId,long itemId,long userId){
        Observable<DelComEntity>delComEntityObservable=RetrofitManager.getInstance().getRetrofit().create(ApiService.class).requestDelComment(commentId,itemId,userId);
        return delComEntityObservable.map(new Function<DelComEntity, BaseEntity>() {
            @Override
            public BaseEntity apply(@NonNull DelComEntity delComEntity) throws Exception {
                return delComEntity;
            }
        });
    }
}
